package top.lywivan.web;

import com.alibaba.fastjson.JSON;
import top.lywivan.pojo.Brand;
import top.lywivan.service.BrandService;
import top.lywivan.utils.BeanFactory;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet(urlPatterns = "/queryAllBrand")
public class QueryAllBrandServlet extends HttpServlet {
    private BrandService brandService= BeanFactory.getBean(BrandService.class);
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            List<Brand> brandList = brandService.queryAllBrand();
            String jsonString = JSON.toJSONString(brandList);
            response.setContentType("application/json;charset=utf-8");
            response.getWriter().write(jsonString);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
